<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>传智健康</title>
    <meta name="description" content="传智健康">
    <meta name="keywords" content="传智健康">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">
    <!-- 引入组件库 -->
    <script type="text/javascript" src="../js/jquery.min.js"></script>
    <script src="../js/vue.js"></script>
    <script src="../plugins/elementui/index.js"></script>
    <script src="../js/axios-0.18.0.js"></script>
    <style>
       .avatar-uploader .el-upload {
           border: 1px dashed #d9d9d9;
           border-radius: 6px;
           cursor:pointer;
           position: relative;
           overflow: hidden;
        }
       .avatar-uploader .el-upload:hover {
          border-color: #409eff;
        }
        .avatar-uploader-icon{
            font-size: 28px;
            color: #8c939d;
            width: 179px;
            height: 178px;
            line-height: 178px;
            text-align: center;
        }
        .avatar{
            width: 178px;
            height: 178px;
            display: block;
        }
        .datatable{
            position: relative;
            box-sizing: border-box;
            -webkit-box-flex: 1;
            width: 100%;
            max-width: 100%;
            font-size: 14px;
            color: rgb(96,98,102);
            overflow: hidden;
            flex: 1 1 0%;
        }
        .datatable td , .datatable th{
            padding: 12px 0;
            min-width: 0;
            -webkit-box-sizing: border-box;
            box-sizing: border-box;
            text-overflow: ellipsis;
            vertical-align: middle;
            position: relative;
            text-align: left;
        }
    </style>
</head>
<body class="hold-transition">
<div id="app">
    <div class="content-header">
        <h1>系统管理<small>菜单管理</small></h1>
        <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>系统管理</el-breadcrumb-item>
            <el-breadcrumb-item>菜单管理</el-breadcrumb-item>
        </el-breadcrumb>
    </div>
    <div class="app-container">
        <div class="box">
           <el-button type="primary" class="buttT" @click="addMenu()">添加一级菜单</el-button>
            <el-tree
                :data="menuData"
                node-key="id">
                <span class="custom-tree-node" slot-scope="{node,data}">
                    <span>{{node.label}}</span>
                    <el-button type="text" size="mini" @click="addChildren(node,data)">添加子菜单</el-button>
                </span>
            </el-tree>
            </div>

        <div id="addMenuDiv">
            <el-dialog title="新增菜单":visible.sync="dialogAddMenuVisble">
                <el-form :model="menu">
                    <el-form-item label="菜单名称" :label-width="formLabelWidth">
                        <el-input v-model="menu.name"></el-input>
                    </el-form-item>
                    <el-form-item label="跳转地址" :label-width="formLabelWidth">
                        <el-input v-model="menu.linkUrl"></el-input>
                    </el-form-item>
                    <el-form-item label="图标" :label-width="formLabelWidth">
                        <el-input v-model="menu.icon"></el-input>
                    </el-form-item>
                </el-form>
                <div slot="footer" class="dialog-footer">
                    <el-button @click="dialogAddMenuVisble=false">取消</el-button>
                    <el-button type="primary" @click="handlerAddMenu()">确定</el-button>
                </div>
            </el-dialog>
        </div>
    </div>
</div>
</body>

<script>
    var vue = new Vue({
        el: '#app',
        data:{
          menuData:[],
            dialogAddMenuVisble:false,
            formLabelWidth:'120px',
            menu: {
                name: '',
                linkUrl: '',
                parentMenuId: null
            }
        },
        created() {
            this.loadMenu();
        },
        methods: {
            //添加子菜单
            addChildren(node,data) {
                this.menu={}
                this.dialogAddMenuVisble=true;
                this.menu.parentMenuId=data.id;
                },

            //弹出添加菜单框
            addMenu() {
                this.menu={}
                this.dialogAddMenuVisble=true;

            },
            //菜单数据保存到数据库
            handlerAddMenu() {
                axios.post("/menu/add.do",this.menu).then((res)=>{
                    this.dialogAddMenuVisble=false;
                    this.$message({
                        message: res.data.message,
                        type: res.data.flag ? 'success' : "error"
                    });
                    this.loadMenu();
                    this.menu.parentMenuId =null;
                })
            },
            // 加载菜单
           loadMenu() {
               axios.get("/menu/getMenu.do?id=0").then((res)=>{
                   this.menuData=res.data.data;
               })
            },
        }
    })
</script>
</html>
